/*
 * @Author: xin.yang
 * @Date: 2019-10-22 11:26:40
 * @Last Modified by: xin.yang
 * @Last Modified time: 2019-10-22 14:34:30
 */
const fs = require("fs");

exports.repeatAllAlbums = (files, callback) => {
  let allAlbums = [];
  if (files.length === 0) return callback(null, allAlbums);
  (function iterator(i) {
    if (i === files.length) {
      return callback(null, allAlbums);
    }
    fs.stat("./uploads/" + files[i], (err, stats) => {
      if (err) {
        callback("找不到文件" + files[i]);
      }
      if (stats.isDirectory()) {
        allAlbums.push(files[i]);
      }
      iterator(i + 1);
    });
  })(0);
};

exports.repeatAllImages = (files, albumName, callback) => {
  let allImages = [];
  if (files.length === 0) return callback(null, allImages);
  (function iterator(i) {
    if (i == files.length) {
      return callback(null, allImages);
    }
    fs.stat("./uploads/" + albumName + "/" + files[i], (err, stats) => {
      if (err) return callback("找不到文件" + files[i], null);
      if (stats.isFile()) {
        allImages.push(files[i]);
      }
      iterator(i + 1);
    });
  })(0);
};
